package com.huatai.vba.execute.action;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;
import com.huatai.vba.dal.jdbc.DBUtils;
import com.huatai.vba.dal.model.VbaFileAction;
import com.huatai.vba.properties.Dbconfig;

/**
 * 工行借口生成程序
 * 
 * @author fanrui16
 *
 */
@Service("icbcInitActionExecutor")
public class IcbcInitActionExecutor extends AbstractIcbcActionExecutor {

	private static final Logger logger = LoggerFactory.getLogger(IcbcInitActionExecutor.class);

	@Override
	public void execute(VbaFileAction action) {
		try {

			String[] tables = new String[] { "hsfundid", "TSGH13812", "tssjshb", "GH13812_zr", "sjshb_zr", "qsjs",
					"tssjsfx100200", "tsjsmxjs946" };
			for (String tableName : tables) {
				vbaExtendsService.cleanTable(tableName);
				logger.info("删除：{}表数据", tableName);
			}

			String fundCodes = this.convertSql(strOne);
			String sql = "select a.vc_seat_id from ttradeseat a, tfundinfo b where a.l_fund_id = b.l_fund_id "
					+ "and a.c_market_no = '1'  and a.c_trade = '1'  and vc_fund_code = any(" + fundCodes + ")"
					+ " group by a.vc_seat_id";
			List<Map<String, Object>> dataList = DBUtils.executeQuery(Dbconfig.TRADEDB, user,
					Dbconfig.getPasswordByUserId(user), sql);
			List<String> arrSeatIDs = Lists.newArrayList();
			for (Map<String, Object> data : dataList) {
				arrSeatIDs.add((String) data.get("vc_seat_id".toUpperCase()));
			}
			for (String seatID : arrSeatIDs) {
				vbaExtendsService.cleanTable("gh" + seatID);
				logger.info("删除：{}表数据", "gh" + seatID);
			}
		} catch (Exception ex) {
			logger.info("系统异常", ex);
		}

	}

}
